package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.entity.ViewTestResultSds;
import com.aaa.service.ViewTestResultSdsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultSds)表控制层
 *
 * @author
 * @since 2022-07-08 10:00:04
 */
@RestController
@RequestMapping("viewTestResultSds")
public class ViewTestResultSdsController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ViewTestResultSdsService viewTestResultSdsService;
    MyReturn myReturn = new MyReturn();

    @RequestMapping("toShowTestResultSds.do")
    public ModelAndView toShowTestResultSds(ModelAndView modelAndView) {
        modelAndView.setViewName("viewTestResultSds");
        return modelAndView;
    }

    @RequestMapping("toReportFormsSds.do")
    public ModelAndView toReportFormsSds(ModelAndView modelAndView) {
        modelAndView.setViewName("reportFormsSds");
        return modelAndView;
    }

    /**
     * 分页查询
     *
     * @param viewTestResultSds 筛选条件
     * @return 查询结果
     */
    @RequestMapping("queryByPage.do")
    public ResponseEntity<Page<ViewTestResultSds>> queryByPage(ViewTestResultSds viewTestResultSds, Integer page, Integer limit) {
        PageRequest pageRequest = PageRequest.of(page - 1, limit);
        return ResponseEntity.ok(this.viewTestResultSdsService.queryByPage(viewTestResultSds, pageRequest));
    }

    /**
     * @param viewTestResultSds
     * @return MyReturn
     * @create by: feng (zhaixing@163.com)
     * @description: 根据id查询对应信息
     * @create time: 2022/7/15 15:48
     */
    @RequestMapping("queryResultById.do")
    public MyReturn queryResultById(ViewTestResultSds viewTestResultSds) {
        ViewTestResultSds result = this.viewTestResultSdsService.queryRequestById(viewTestResultSds);
        myReturn.setData(result);
        return getSuccessResult(myReturn);
    }

    /**
     * @param
     * @return MyReturn
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有数据 报表统计
     * @create time: 2022/7/15 16:17
     */
    @RequestMapping("sdsCount.do")
    public MyReturn colorCount() {
        Map<String, Integer> map = this.viewTestResultSdsService.queryAllPlanSds();
        myReturn.setData(map);
        return getSuccessResult(myReturn);
    }

    /**
     * @param
     * @return MyReturn
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有 下拉列表
     * @create time: 2022/7/19 21:08
     */
    @RequestMapping("pullSds.do")
    public MyReturn pullSds() {
        List<ViewTestResultSds> viewTestResultSds = this.viewTestResultSdsService.queryAllResultSds();
        myReturn.setData(viewTestResultSds);
        return getSuccessResult(myReturn);
    }
    /**
     * @create by: feng (zhaixing@163.com)
     * @description: 删除
     * @create time: 2022/7/22 20:10
     * @param testerId
     * @return
     */
    @RequestMapping("deleteResultSds.do")
    public MyReturn deleteResultSds(String testerId){
        boolean b = this.viewTestResultSdsService.deleteResultById(testerId);
        if (b) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

}

